//
//  MeSmallCell.m
//  LingQian
//
//  Created by wtjr on 2018/1/22.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "MeSmallCell.h"

@interface MeSmallCell()
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) BaseImageView *iconImageView;
@property (nonatomic, strong) BaseLabel *titleLabel;
@end

@implementation MeSmallCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"MeSmallCell";
    MeSmallCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[MeSmallCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - init

- (void)initData {
    self.backgroundColor = kCOLOR_clear;
}

- (void)initSubView {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
}

#pragma mark - Method


#pragma mark - Interface



#pragma mark - Setter

- (void)setIndexPath:(NSIndexPath *)indexPath {
    _indexPath = indexPath;
}

- (void)setViewModel:(MeViewModel *)viewModel {
    _viewModel = viewModel;
    NSDictionary *dic = _indexPath.section == 1 ? _viewModel.dateSource1[_indexPath.row] : _viewModel.dateSource2[_indexPath.row];
    self.iconImageView.imageName = dic[@"image"];
    self.titleLabel.text = dic[@"title"];
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        
        BaseImageView *iconImageView = [BaseImageView new];
        self.iconImageView = iconImageView;
        [_mainView addSubview:iconImageView];
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.centerY.equalTo(@0);
            make.width.height.equalTo(@20);
        }];
        
        BaseLabel *titleLabel = [BaseLabel new];
        [titleLabel setLabelStyle:@"" textColor:KCOLOR_nornalFont textFont:kFONT_mainFont(14) texrAlignment:NSTextAlignmentLeft];
        self.titleLabel = titleLabel;
        [_mainView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconImageView.mas_right).offset(10);
            make.centerY.equalTo(@0);
            make.height.equalTo(@20);
        }];
    }
    return _mainView;
}

@end
